package com.huike.business.service.impl;


import cn.hutool.core.bean.BeanUtil;
import com.huike.business.domain.TbBusiness;
import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessMapper;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    private TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;
    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    /**
     * 查询商机跟进记录列表
     * @param id
     * @return
     */
    @Override
    public List<TbBusinessTrackRecord> getList(Long id) {
        List<TbBusinessTrackRecord> list = tbBusinessTrackRecordMapper.getList(id);
        return list;
    }

    /**
     * 添加商机记录
     * @param businessTrackVo
     * @return
     */
    @Override
    public AjaxResult add(BusinessTrackVo businessTrackVo) {
        Date nowDate = DateUtils.getNowDate();
        String username = SecurityUtils.getUsername();
        //修改商机
        TbBusiness tbBusiness = new TbBusiness();
        BeanUtil.copyProperties(businessTrackVo,tbBusiness);
        tbBusiness.setId(businessTrackVo.getBusinessId());
        tbBusiness.setUpdateTime(nowDate);
        tbBusinessMapper.updateTbBusiness(tbBusiness);
        //保存记录
        TbBusinessTrackRecord tbBusinessTrackRecord = new TbBusinessTrackRecord();
        BeanUtil.copyProperties(businessTrackVo,tbBusinessTrackRecord);
        tbBusinessTrackRecord.setCreateTime(nowDate);
        tbBusinessTrackRecord.setCreateBy(username);
        tbBusinessTrackRecordMapper.add(tbBusinessTrackRecord);
        return AjaxResult.success("添加成功");
    }
}
